﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ChanExt;
using C.Unite;
using C.Entities;

namespace ArtLand.OA.Project.HR
{
    public partial class HR_ReqempChange : CommonPageBase
    {
        public string ContentS = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBaseHelper.BindDrp(Drp_STTYPE, EnumData.DataBaseEunm.JobTYPE);

                FormInfo.ShowTriggerWin(Window1, txt_Auditer, hid_AuditUID, "/PublicModel/SelectUsers.aspx?single=1", "选择审批人");
                btnClose.OnClientClick = ActiveWindow.GetHideReference();
                LoadData();
            }
        }

        protected void LoadData()
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {

                HR_REQEMP Sam = TbsDbSession.Default.From<HR_REQEMP>().Where(HR_REQEMP._.ID == int.Parse(Request["id"])).ToFirst();
                if (Sam != null)
                {
                    txt_EMPQTY.Text = Sam.EMPQTY.Value.ToString();
                    txt_OTHREQ.Text = Sam.OTHREQ;
                    Drp_STTYPE.SelectedValue = Sam.STTYPE;
                    txt_Auditer.Text = Sam.Auditer;
                    hid_AuditUID.Text = Sam.AuditUid;
                }
                if (!string.IsNullOrEmpty(Request["s"]))
                {
                    tool1.Hidden = false;
                    tool2.Hidden = true;
                    Drp_STTYPE.Enabled = false;
                    txt_EMPQTY.Readonly = true;
                    txt_OTHREQ.Readonly = true;
                }
                else
                {
                    tool1.Hidden = true;
                    tool2.Hidden = false;
                }
            }
            else
            {
                tool1.Hidden = true;
                tool2.Hidden = false;
            }
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            int returnvalue = 0;
            HR_REQEMP Sam = new HR_REQEMP();
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                Sam.ID = int.Parse(Request["id"]);
                Sam.Attach();
                Sam.STTYPE = Drp_STTYPE.SelectedValue;
                Sam.OTHREQ = txt_OTHREQ.Text;
                Sam.EMPQTY =int.Parse(txt_EMPQTY.Text);
                Sam.Auditer = txt_Auditer.Text;
                Sam.AuditUid = hid_AuditUID.Text;
                returnvalue = TbsDbSession.Default.Update<HR_REQEMP>(Sam);
            }
            else
            {
                Sam.DeAttach();
                Sam.STTYPE = Drp_STTYPE.SelectedValue;
                Sam.STATUS = 0;
                Sam.OTHREQ = txt_OTHREQ.Text;
                Sam.EMPQTY = int.Parse(txt_EMPQTY.Text);
                Sam.Adder = CookInfo.EAdminTrueName();
                Sam.AddID = CookInfo.EAdminid();
                Sam.AddTime = DateTime.Now;
                Sam.Auditer = txt_Auditer.Text;
                Sam.AuditUid = hid_AuditUID.Text;
                returnvalue = TbsDbSession.Default.Insert<HR_REQEMP>(Sam);
            }
            if (returnvalue > 0)
            {
                Alert.Show("更新成功！", "提示", ActiveWindow.GetHideRefreshReference());
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"]);
            HR_REQEMP vc = new HR_REQEMP();
            vc.ID = id;
            vc.Attach();
            vc.STATUS = 1;
            TbsDbSession.Default.Update<HR_REQEMP>(vc);

            Alert.Show("审批结束", "提示", ActiveWindow.GetHideRefreshReference());
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"]);
            HR_REQEMP vc = new HR_REQEMP();
            vc.ID = id;
            vc.Attach();
            vc.STATUS = 2;
            TbsDbSession.Default.Update<HR_REQEMP>(vc);
            Alert.Show("审批结束", "提示", ActiveWindow.GetHideRefreshReference());
        }



    }
}